package com.xyw.code.springcloudsentinel;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class TestService {

    //blockHandler 限流调用的方法
    //fallback 熔断调用
    //fallback 只有配置了降级策略 才会进fallback方法
    @SentinelResource(value = "doSomeThing1",fallback="doSomeThing1Fallback",blockHandler = "exceptionHandler")
    public void doSomeThing(String str) {
        log.info(str);
//        throw new RuntimeException("发生异常");
    }

    // 限流与阻塞处理
    public void exceptionHandler(String str, BlockException ex) {
        log.error( "blockHandler：" + str, ex);
    }


    public void doSomeThing1Fallback(String str) {
        log.error("fallbackHandler11：" + str);
    }

}